<?php

$list = $_POST['list'];
$action = $_POST['action'];

$list = split("\n",$list);
if($action=='encode'){
    foreach ($list as $uid) {
        echo api_encode_uid($uid)."\n";
    }
}
else if($action=="decode"){
    foreach ($list as $uid) {
        echo api_decode_uid($uid)."\n";
    }
}
else echo "Unsupported action!";

//UKתUID
function api_decode_uid($sid) {
    if (! is_int ( $sid ) && ! is_numeric ( $sid )) {
        return false;
    }
    $sid ^= 282335;
    $uid = ($sid & 0x00ff0000) << 8;
    $uid += ($sid & 0x000000ff) << 16;
    $uid += (($sid & 0xff000000) >> 16) & 0x0000ff00;
    $uid += ($sid & 0x0000ff00) >> 8;
    return $uid;
}
//UIDתUK
function api_encode_uid($uid) {
    $sid = ($uid & 0x0000ff00) << 16;
    $sid += (($uid & 0xff000000) >> 8) & 0x00ff0000;
    $sid += ($uid & 0x000000ff) << 8;
    $sid += ($uid & 0x00ff0000) >> 16;
    $sid ^= 282335;
    return $sid;
}



?>